//
// Created by Tan Ke on 2023/12/20.
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char* defangIPaddr(char* address)
{
    char* result = (char* )malloc(sizeof(char) * 22);
    int index = 0;
    memset(result, 0, sizeof(char) * 22);

    for (int i = 0; i < strlen(address); i ++) {
        if (address[i] != '.') {
            result[index] = address[i];
            index += 1;
        } else {
            result[index] = '[';
            index += 1;
            result[index] = '.';
            index += 1;
            result[index] = ']';
            index += 1;
        }
    }

    return result;
}

int main(void)
{
    printf("%s\n", defangIPaddr("192.168.2.12"));

    return 0;
}

